package JackSu.project_model;

/**
 * MethodFactoryTest
 *
 * @author Syzer
 * @Description 工厂方法模式
 * @Date 2021/7/8 16:37
 */
public class MethodFactoryTest {

    private interface Product {
        void show();
    }

    private static class IProduct implements Product {
        @Override
        public void show() {
            System.out.println("具体产品1");
        }
    }

    private static class QProduct implements Product {
        @Override
        public void show() {
            System.out.println("具体产品2");
        }
    }

    private interface Factory {
        Product newProduct();
    }

    private static class IFactory implements Factory {
        @Override
        public Product newProduct() {
            System.out.println("具体工厂1");
            return new IProduct();
        }
    }

    private static class QFactory implements Factory {
        @Override
        public Product newProduct() {
            System.out.println("具体工厂2");
            return new QProduct();
        }
    }

    public static void main(String[] args) {
        Factory factory = new IFactory();
        Product product = factory.newProduct();
        product.show();

        Factory factory1 = new QFactory();
        Product product1 = factory1.newProduct();
        product1.show();
    }
}
